package site.timers.chat.service;

import cn.hutool.core.util.ObjectUtil;
import org.springframework.stereotype.Service;
import site.timers.chat.enums.UserEnum;
import site.timers.chat.exception.ApplicationException;
import site.timers.chat.pojo.dto.LoginDto;
import site.timers.chat.pojo.vo.LoginVo;
import site.timers.chat.pojo.vo.UserVo;

/**
 * @Classname UserService
 * @Description TODO
 * @Version 1.0.0
 * @Date 2025/8/14 13:50
 * @Author twl
 */
@Service
public class UserService {

    public LoginVo login(LoginDto loginDto) {
        UserEnum user = UserEnum.getByAccountAndPassword(loginDto.getAccount(), loginDto.getPassword());
        if (ObjectUtil.isNull(user)) {
            throw new ApplicationException("用户名或密码错误");
        }

        return new LoginVo(user.getToken(), new UserVo(user.getAccount(), user.getNickName()));
    }
}
